*Analyses on the destination of leavers (Section 5)

use cses2to4_40cases, clear

*-------------------------------------------------------------------------------
*0. Preparation of variables
*-------------------------------------------------------------------------------

tab cntry, gen (dcntry)
tab cntelec, gen (dcntelec)

recode educ 9=.

tab clasdt
tab clasdt, nol
recode clasdt 1/2=1 3=3 4=2 5/8=3, gen (clas3soc_wcserpro) 
label var clas3soc_wcserpro "Social class, 3 cat, socio-cu" 
lab def clas3soc_wcserpro 1 "Workers" 2 "Socio-cultural" 3"Other non-workers" 
lab val clas3soc_wcserpro clas3soc_wcserpro
tab clas3soc_wcserpro


*Dependent variable

gen switch_d=.
replace switch_d=1 if (preparty5abs==2 & party5abs==0) |  (preparty5abs==2 & party5abs==3) /*Non left and Populists together*/
replace switch_d=2 if preparty5abs==2 & party5abs==10 /*Greens*/
replace switch_d=3 if preparty5abs==2 & party5abs==11 /*Radical Left*/
replace switch_d=4 if preparty5abs==2 & party5abs==2 /*Social democrats*/
replace switch_d=5 if preparty5abs==2 & party5abs==4 /*Not voting*/
label var switch_d  "Away from mainstream left, detailed" 
lab def switch_d 1"To non left" 2"To Greens" 3"To Radical Left" 4"Stable SD supporters" 5"To non-voting" 
lab val switch_d switch_d
tab switch_d

gen switch_dpop=.
replace switch_dpop=1 if (preparty5abs==2 & party5abs==0) /*Non left*/
replace switch_dpop=2 if preparty5abs==2 & party5abs==10 /*Greens*/
replace switch_dpop=3 if preparty5abs==2 & party5abs==11 /*Radical Left*/
replace switch_dpop=4 if preparty5abs==2 & party5abs==2 /*Social democrats*/
replace switch_dpop=5 if preparty5abs==2 & party5abs==4 /*Not voting*/
replace switch_dpop=6 if (preparty5abs==2 & party5abs==3) /*Populists*/
label var switch_dpop  "Away from mainstream left, detailed with populists" 
lab def switch_dpop 1"To non left" 2"To Greens" 3"To Radical Left" 4"Stable SD supporters" 5"To non-voting" 6"To populists"
lab val switch_dpop switch_dpop
tab switch_dpop

gen right_all=.
replace right_all=1 if switch_dpop==1  
replace right_all=0 if switch_dpop==2  | switch_dpop==3  | switch_dpop==5  | switch_dpop==6
label var right_all "Mainstream right vs other leavers" 
lab def right_all  0"All other" 1 "Mainstream right" 
lab val right_all right_all 
tab right_all

gen nonvoting_all=.
replace nonvoting_all=1 if switch_d==5
replace nonvoting_all=0 if switch_d==1  | switch_d==2  | switch_d==3  
label var nonvoting_all  "Non voting vs other leavers" 
lab def nonvoting_all  0"All other" 1 "Non voting" 
lab val nonvoting_all nonvoting_all 
tab nonvoting_all

gen radleft_all=.
replace radleft_all=1 if switch_d==3
replace radleft_all=0 if switch_d==1  | switch_d==2  | switch_d==5
label var radleft_all  "Radical Left vs other leavers" 
lab def radleft_all  0"All other" 1 "Radical Left 
lab val radleft_all radleft_all 
tab radleft_all

gen green_all=.
replace green_all=1 if switch_d==2
replace green_all=0 if switch_d==1  | switch_d==3  | switch_d==5
label var green_all  "Greens vs other leavers" 
lab def green_all  0"All other" 1 "Greens" 
lab val green_all green_all 
tab green_all

gen popu_all=.
replace popu_all=1 if switch_dpop==6  
replace popu_all=0 if switch_dpop==1  |switch_dpop==2  | switch_dpop==3  | switch_dpop==5  
label var popu_all  "Populists vs other leavers" 
lab def popu_all  0"All other" 1 "Populists" 
lab val popu_all popu_all 
tab popu_all


*----------------------------------------------------------------------------------
*1. Regressions
*----------------------------------------------------------------------------------

*1. Mainstream right and others
xtmelogit right_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat ///
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:,
estat icc
estadd scalar icc=r(icc2)
estimates store mright

*2. Non voting 
xtmelogit nonvoting_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat ///
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. ///
|| cntry: || cntelec:, 
estat icc
estadd scalar icc=r(icc2)
estimates store mnon

*3. Radical Left
xtmelogit radleft_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat ///
if dcntry1!=1 & dcntry7!=1 & dcntelec37!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:,  
estat icc
estadd scalar icc=r(icc2)
estimates store mrad

*4. Greens
xtmelogit green_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat ///
if dcntry9!=1 & dcntry7!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:,   
estat icc
estadd scalar icc=r(icc2)
estimates store mgreen

*5. Populists
xtmelogit popu_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat ///
if dcntelec2!=1 & dcntelec3!=1 & dcntry14!=1 & dcntelec17!=1 & dcntry10!=1 & dcntry9!=1 & dcntelec38!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. ///
|| cntry: || cntelec:, 
estat icc
estadd scalar icc=r(icc2)
estimates store mpop

*1b. inter Mainstream right and others
xtmelogit right_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat i.unionm#i.clas3soc_wcserpro ///
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:,
estat icc
estadd scalar icc=r(icc2)
estimates store mrightinter

*2b. inter Non voting 
xtmelogit nonvoting_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat i.unionm#i.clas3soc_wcserpro ///
if clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. ///
|| cntry: || cntelec:, 
estat icc
estadd scalar icc=r(icc2)
estimates store mnoninter

*3b. inter Radical Left
xtmelogit radleft_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat i.unionm#i.clas3soc_wcserpro ///
if dcntry1!=1 & dcntry7!=1 & dcntelec37!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:, 
estat icc
estadd scalar icc=r(icc2)
estimates store mradinter

*4b. inter Greens
xtmelogit green_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat i.unionm#i.clas3soc_wcserpro ///
if dcntry9!=1 & dcntry7!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. /// 
|| cntry: || cntelec:,  
estat icc
estadd scalar icc=r(icc2)
estimates store mgreeninter

*5b. inter Populists
xtmelogit popu_all i.unionm ib1.clas3soc_wcserpro c.age i.gender i.educ ib4.locat i.unionm#i.clas3soc_wcserpro ///
if dcntelec2!=1 & dcntelec3!=1 & dcntry14!=1 & dcntelec17!=1 & dcntry10!=1 & dcntry9!=1 & dcntelec38!=1 & clas3soc_wcserpro!=. & unionm!=. & age!=. & gender!=. & locat!=. & educ!=. ///
|| cntry: || cntelec:, 
estat icc
estadd scalar icc=r(icc2)
estimates store mpopinter

*Appendix 9 
esttab mright mnon mrad mgreen mpop mrightinter mnoninter mradinter mgreeninter mpopinter using Output7.rtf, replace se aic (1) bic (1) scalars(icc ll df_m) sfmt(3 1 0) b(3) nobaselevels nogaps /// 
transform (ln*: exp(@)^2 exp(@)^2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) 


*----------------------------------------------------------------------------------
*2. Marginal effects
*----------------------------------------------------------------------------------

*Figure 6

estimates restore mright 
quietly margins rb3.clas3soc_wcserpro, contrast predict (mu fixedonly) 
marginsplot, recast (scatter) yline(0) title("Mainstream right and others") ///
ytitle("") xtitle("") xlabel (0.75 " " 1"Workers" 2 "Socio-cultural" 2.25 " ", notick) ///
xsize (1.5) ysize (2) yscale(range(0.15 -0.15))  ylabel(#6)  plotopts(scheme(s1mono)) 
graph save mainright_ame, replace

estimates restore mnon 
quietly margins rb3.clas3soc_wcserpro,  contrast predict (mu fixedonly)
marginsplot, recast (scatter) yline(0) title("Non-voting")  ///
ytitle("") xtitle("") xlabel (0.75 " " 1"Workers" 2 "Socio-cultural" 2.25 " ", notick) ///
xsize (1.5) ysize (2) yscale(range(0.15 -0.15))  ylabel(#6)  plotopts(scheme(s1mono)) 
graph save nonvoting_ame, replace

estimates restore mrad 
quietly margins rb3.clas3soc_wcserpro,  contrast predict (mu fixedonly)
marginsplot, recast (scatter) yline(0) title("Radical Left") ///
ytitle("") xtitle("") xlabel (0.75 " " 1"Workers" 2 "Socio-cultural" 2.25 " ", notick) ///
xsize (1.5) ysize (2) yscale(range(0.15 -0.15))  ylabel(#6)  plotopts(scheme(s1mono))  
graph save radleft_ame, replace

estimates restore mgreen 
quietly margins rb3.clas3soc_wcserpro,  contrast predict (mu fixedonly)
marginsplot, recast (scatter) yline(0) title("Greens") ///
ytitle("") xtitle("") xlabel (0.75 " " 1"Workers" 2 "Socio-cultural" 2.25 " ", notick) ///
xsize (1.5) ysize (2) yscale(range(0.15 -0.15))  ylabel(#6)  plotopts(scheme(s1mono)) 
graph save green_ame, replace

estimates restore mpop
quietly margins rb3.clas3soc_wcserpro,  contrast predict (mu fixedonly)
marginsplot, recast (scatter) yline(0) title("Radical Right") ///
ytitle("") xtitle("") xlabel (0.75 " " 1"Workers" 2 "Socio-cultural" 2.25 " ", notick) ///
xsize (1.5) ysize (2) yscale(range(0.15 -0.15))  ylabel(#6)  plotopts(scheme(s1mono)) 
graph save popu_ame, replace

gr combine mainright_ame.gph nonvoting_ame.gph radleft_ame.gph green_ame.gph popu_ame.gph, scheme(s1mono) 
graph save newvoting_ame, replace


*Table 5

estimates restore mright 
margins, dydx(union) contrast predict (mu fixedonly)

estimates restore mnon 
margins, dydx(union) contrast predict (mu fixedonly)

estimates restore mrad 
margins, dydx(union) contrast predict (mu fixedonly)

estimates restore mgreen 
margins, dydx(union) contrast predict (mu fixedonly)

estimates restore mpop
margins, dydx(union) contrast predict (mu fixedonly)


*Table 6: with interaction

estimates restore mrightinter 
mlincom, clear
margins, at (unionm=(0 1) clas3soc_wcserpro=(1 2 3)) post predict (mu fixedonly)
mlincom (4-1) /*union effect for workers*/
mlincom (5-2) /*union effect for socio-cu*/
mlincom (6-3) /*union effect for other non-workers*/
mlincom (4-1)- (5-2) /*diff workers - socio-cu*/
mlincom (4-1)- (6-3) /*diff workers - other non workers*/
mlincom (5-2)- (6-3) /*diff sociocu - other non workers*/

estimates restore mnoninter 
mlincom, clear
margins, at (unionm=(0 1) clas3soc_wcserpro=(1 2 3)) post predict (mu fixedonly)
mlincom (4-1) 
mlincom (5-2) 
mlincom (6-3) 
mlincom (4-1)- (5-2) 
mlincom (4-1)- (6-3) 
mlincom (5-2)- (6-3) 

estimates restore mradinter 
mlincom, clear
margins, at (unionm=(0 1) clas3soc_wcserpro=(1 2 3)) post predict (mu fixedonly)
mlincom (4-1) 
mlincom (5-2) 
mlincom (6-3) 
mlincom (4-1)- (5-2) 
mlincom (4-1)- (6-3) 
mlincom (5-2)- (6-3) 

estimates restore mgreeninter 
mlincom, clear
margins, at (unionm=(0 1) clas3soc_wcserpro=(1 2 3)) post predict (mu fixedonly)
mlincom (4-1) 
mlincom (5-2) 
mlincom (6-3) 
mlincom (4-1)- (5-2) 
mlincom (4-1)- (6-3) 
mlincom (5-2)- (6-3) 

estimates restore mpopinter
mlincom, clear
margins, at (unionm=(0 1) clas3soc_wcserpro=(1 2 3)) post predict (mu fixedonly)
mlincom (4-1) 
mlincom (5-2) 
mlincom (6-3) 
mlincom (4-1)- (5-2) 
mlincom (4-1)- (6-3) 
mlincom (5-2)- (6-3) 
